#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project : gtmsAutoTestProject
@File    : customer_api.py
@IDE     : PyCharm 
@Author  : Mario
@Date    : 2022/4/26 18:15 
@Describe: 中台会员相关接口
"""
from Comm.tools.toolsControl import ToolsHandler
from APIs.middleApi.base_middle_api import BaseMiddleApi


class CustomerApi(BaseMiddleApi):
    def __init__(self, environment):
        super().__init__(environment)

    def get_customer_info(self, brandCode, phone):
        """
        获取会员基础信息
        :param brandCode: 品牌编码
        :param phone: 手机号
        :return:
        """
        payload = '{"brandCode":"' + str(brandCode) + '","phone":"' + phone + '"}'
        response = self.http_requests('catering-backend/customer/info/info', payload)
        return response

    def get_customer_list(self, brandCode, phone):
        """
        获取会员列表
        :param brandCode: 品牌编码
        :param phone: 手机号
        :return:
        """
        payload = '{"brandCode":"' + str(brandCode) + '","phone":"' + phone + '"}'
        response = self.http_requests('scrm-admin/customer/base/list', payload)
        return response

    def customer_point_operation(self, brandCode, phone, changePoint):
        """
        会员积分操作
        :param brandCode: 品牌编码
        :param phone: 手机号
        :param changePoint: 操作积分，可以减
        :return:
        """
        vip_info = self.get_customer_info(brandCode, phone)
        customerId = str(ToolsHandler.get_json_result(vip_info, '$..customerId'))
        payload = '{"brandCode":"' + brandCode + '","customerId":"' + customerId + '","changePoint":"' + changePoint + '"}'
        response = self.http_requests('scrm-admin/customer/point/save', payload)
        return response


if __name__ == '__main__':
    test = CustomerApi('sit')
    test.get_customer_list('823884', '18682241673')
